<template>
	<view class="content1">
		<navbar title="余额变动明细" @goBack="goBack"></navbar>
		<view class="nav">
			<view class="txt" @click="tabChange('all')" :class="[activeTab=='all'?'select':'']">全部
			</view>
			<view class="txt" @click="tabChange('add')" :class="[activeTab=='add'?'select':'']">收入
			</view>
			<view class="txt" @click="tabChange('reduce')" :class="[activeTab=='reduce'?'select':'']">支出
			</view>
		</view>
		<view class="package-box" style="padding-bottom: 90rpx">
			<view v-for="(item, index) in List" :key="index" class="gift-box">
				<view class="white-content" style="font-size: 28rpx"> {{ item.type=='adminChange' ?'官方改动':item.type }}
				</view>
				<view class="image-box">
					<view class="lflex">
						<text class="price">账户充值:{{ item.trade_num }}</text>
					</view>
					<view class="lflex">
						<text class="price" style="color: rgba(255, 255, 255, 0.65);">{{ convertDateTime(item.created_at) }}
						</text>
					</view>
				</view>
				<view class="coinbg">
					<text class="txt">+</text>
					<image class="icon" src="/static/owo/coin.png"></image>
					<text class="num">600</text>
				</view>
			</view>
		</view>

		<view class="empty-page" v-if="List.length==0">
			<view class="nofull">
				<image src="../../static/icons/package/nofull.png" class="nofullimg"></image>
				<text class="notitle">暂无数据</text>
			</view>
		</view>
	</view>
</template>

<script>
	import navbar from '@/wxcomponents/navbar'
	import moment from "moment";
	import {
		billslist,
		walletrecord
	} from "@/api/user";
	export default {
		components: {
			navbar
		},
		data() {
			return {
				activeTab:'all',
				List: [],
				total: 0,
				page: 1
			};
		},
		onLoad: function(options) {
			this.getwalletrecord();
		},
		onReachBottom() {
			if (this.List.length < this.total) {
				++this.page
				this.getwalletrecord();
			}
		},
		async onPullDownRefresh() {
			this.page = 1
			await this.getwalletrecord();
			uni.stopPullDownRefresh()
		},
		methods: {
			tabChange(name) {
				this.activeTab = name
			},
			convertDateTime(iosDate) {
				if (!iosDate) {
					return "-";
				}
				const date = new Date(iosDate);
				const year = date.getFullYear();
				const month = ("0" + (date.getMonth() + 1)).slice(-2); // 月份是从0开始的
				const day = ("0" + date.getDate()).slice(-2);
				const hours = ("0" + date.getHours()).slice(-2);
				const minutes = ("0" + date.getMinutes()).slice(-2);
				const seconds = ("0" + date.getSeconds()).slice(-2);

				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
			goBack() {
				uni.navigateBack({
					delta: 1,
				});
			},
			// 未申请
			async getwalletrecord() {
				if (this.loading) {
					return
				}
				this.loading = true
				var obj = {
					page: this.page,
					size: 10,
					unit: "score", // 动车票ticket z元素"
				}
				const res = await walletrecord(obj);
				const data = res.data || {};
				const items = data.items || [];
				this.List = this.List.concat(items);
				this.total = data.total
				this.loading = false
			},
		},
	};
</script>

<style lang="scss">
	@import "src/static/scss/common";

	.package-box {
			display: flex;
			flex-direction: column;
		
	}

	.nav {
		display: flex;
		justify-content: space-around;
		// width: 490rpx;
		margin-top: 20rpx;

		.txt {
			display: inline-block;
			width: 132rpx;
			height: 44rpx;
			line-height: 44rpx;
			text-align: center;
			position: relative;
			color: #ffffff;
			font-size: 28rpx;
		}

		.select {
			background-image: url("/static/owo/navselect.png");
			background-position: 0 0;
			background-repeat: no-repeat;
			background-size: 100%;
			color: #FFDD86;
		}
	}

	.gift-box {
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		padding: 24rpx;
		background-color:#42424E;
		margin: 24rpx;
		border-radius: 12rpx;
		position: relative;
		border: solid 1rpx rgba(255, 255, 253, 0.31);

		.image-box {
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			position: relative;

			.price {
				font-size: 23rpx;
				color: #a1a1a1;
			}
		}

		.lflex {
			width: 100%;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			margin-top: 16rpx;
		}
		.coinbg {
			position: absolute;
			right: 30rpx;
			top: 50%;
			transform: translateY(-50%);
			display: flex;
			flex-direction: row;
			align-items: center;
			color: #ffffff;
			font-size: 36rpx;
			font-weight: bold;
			.icon {
				width: 36rpx;
				height: 36rpx;
				margin: 0 4rpx;
			}
			
		}
	}

	.app-container {
		flex-direction: column;
	}
</style>